function init() {
	
	gameState = new GameState();
	
	var imgs = _("img", _("#divMiniGame")[0]);
	for (var i = 0; i < imgs.length; i++) {
		consoleImages[imgs[i].id] = imgs[i];
	}
	
	// center
	_("#divTitle").layerCenter();
	_("#divGameSelection").layerCenter();
	_("#divMiniGame").layerCenter();
	
	// hidden
	_("#divGameSelection").hide();
	_("#divMiniGame").hide();
	
	// hook event handler
	document.onkeydown = keyDownHandler;
	if (document.layers) {
		document.captureEvents(Event.KEYDOWN);
	}
	document.onkeyup = keyUpHandler;
	if (document.layers) {
		document.captureEvents(Event.KEYUP);
	}
	
	gameState.currentGame.init();
	gameState.gameTimer = setTimeout("mainGameLoop()", 42);
}

function startMiniGame(_name) {
	gameState.reset();
	_("#divStatusArea")[0].innerHTML = "Score: " + gameState.score;
	
	var currGame;
	switch (_name) {
		case 'cosmicSquirrel':
			currGame = new CosmicSquirrel();
		case 'deathtrap':
			currGame = new Deathtrap();
		case 'refluxive':
			currGame = new Refluxive();
	}
	if (typeof currGame !== 'undefined') {
		gameState.currentGame = currGame;
		gameState.currentGame.init();
	}
	
	// show the game and hide the selection screen.
	gameState.currentMode = "miniGame";
	drawConsole();
	_("#divGameSelection").hide();
	_("#divMiniGame").css('display', 'block');
}

function mainGameLoop() {
	clearTimeout(gameState.gameTimer);
	gameState.gameTimer = null;
	frameZIndexCounter = 0;
	if (gameState.currentMode === 'miniGame') {
		updateLights();
		updateHands();
		_("#divStatusArea")[0].innerHTML = 'Score: ' + gameState.score;
	}
	gameState.currentGame.processFrame();
	gameState.getTimer = setTimeout("mainGameLoop()", 42);
}

function blit(_img, _x, _y) {
	_img.style.left = _x + 'px';
	_img.style.top = _y + 'px';
	_img.style.zIndex = frameZIndexCounter;
	_img.style.display = "block";
	frameZIndexCounter++;
}
